<template>
  <div class="top-title" ref="target">
    <h1>{{ areaTitle }}</h1>
    <div class="top-count">
      <div>
        <header>用户台区</header>
        <h2 ref="areaRef">{{ userArea }}</h2>
      </div>
      <div>
        <header>用户总数</header>
        <h2 ref="countRef">{{ userTotal }}</h2>
      </div>
      <div>
        <header>时间分布</header>
        <h2>{{ userTime }}</h2>
      </div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref, defineProps } from "vue";
import { CountUp } from "countup.js";
const props = defineProps({
  areaTitle: {
    type: String,
    required: true,
  },
  userArea: {
    type: String || Number,
    required: true,
  },
  userTotal: {
    type: String || Number,
    required: true,
  },
  userTime: {
    type: String,
    required: true,
  },
});
const areaRef = ref(null);
const countRef = ref(null);
onMounted(() => {
  new CountUp(areaRef.value, props.userArea.value).start();
  new CountUp(countRef.value, props.userTotal.value).start();
});
</script>

<style lang="scss" scoped>
.top-title {
  width: 100%;
  height: 45%;
  padding-top: 20px;
  h1 {
    margin: 26px;
  }
  .top-count {
    width: 100%;
    height: 100%;
    padding-top: 20px;
    display: flex;
    justify-content: space-around;
    header {
      font-weight: bold;
      font-size: 20px;
    }
    h2 {
      margin-top: 20px;
      font-size: 30px;
      font-weight: bold;
    }
  }
}
</style>
